import { checkToken } from '@/utils'
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      redirect: '/map',
      component: HomeView,
      children: [
        {
          path: 'map',
          name: 'map',
          component: () => import('@/views/Map/index.vue')
        },
        {
          path: 'config',
          name: 'config',
          component: () => import('@/views/Config/index'),
          children: [
            {
              path: 'camera',
              name: 'camera',
              component: () => import('@/views/Config/components/Camera')
            },
            {
              path: 'device',
              name: 'device',
              component: () => import('@/views/Config/components/Device')
            }
          ]
        }
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/LoginPage.vue'),
      meta: {
        title: '登录'
      }
    },
    {
      path: '/home',
      name: 'history',
      component: () => import('@/views/StatisticAnalysis'),
      meta: {
        title: ''
      }
    },
    {
      path: '/role',
      name: 'role',
      component: () => import('@/views/Permission/RoleView.vue'),
      meta: {
        title: '角色列表'
      }
    },
    {
      path: '/user',
      name: 'user',
      component: () => import('@/views/Permission/UserView.vue'),
      meta: {
        title: '用户列表'
      }
    }
  ]
})

checkToken(router)

export default router
